<%--
  Created by IntelliJ IDEA.
  User: zhangkeke
  Date: 2022/10/10
  Time: 20:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/jcript/jquery-1.7.2.js"></script>
  <script>
    $(function (){
        $("#inp2").blur(function (){
            var reg1 = /^[\d]{18}$/
            var inp2 = $("#inp2").val()
            if(!reg1.test(inp2)){
                $("#sp2").text("身份证格式不正确")
            }
        })
        $("#inp2").focus(function (){
            $("#sp2").text("")
        })

        $("#inp3").blur(function (){
            var reg2 = /^1[\d]{10}$/
            var inp3 = $("#inp3").val()
            if(!reg2.test(inp3)){
                $("#sp3").text("手机号格式不正确")
            }
        })
        $("#inp3").focus(function (){
            $("#sp3").text("")
        })




        $("#btn").click(function (){
            var username = $("#inp1").val()
            var id_number = $("#inp2").val()
            var telephone = $("#inp3").val()
            $.ajax({
                url:"/openAccount",
                data:{username:username,id_number:id_number,telephone:telephone},
                dataType:"json",
                success:function (data){
                    if(data==telephone){
                        $("#sub").attr("disabled",false)
                        $("#sp4").text("开户成功，请您去设置账号支付密码")
                        $("#sub").click(function (){
                            location.href="http://localhost:8087/pages/account/set_password.jsp?telephone="+telephone;
                        })

                    }else {
                        var flag = confirm("开户失败，一类账号已经开过户，不允许再次开户，点击确定查看已存在账号，点击取消，返回首页")
                        if(flag){
                            location.href="/showAccount"
                        }else {
                            location.href="/pages/userMenu.jsp"
                        }
                    }

                }
            })
        })




    })
  </script>
</head>
<body>
<div style="position: relative;left: 550px;top: 150px">
    <h3>开户</h3>
    <label>姓名</label>
    <input type="text" id="inp1" name="username" placeholder="请输入您的真实姓名"><br>
    <label>身份证号</label>
    <input type="text" id="inp2" name="id_number"><span id="sp2" style="color: red" ></span><br>
    <label>手机号</label>
    <input type="text" id="inp3" name="telephone"><span id="sp3" style="color: red"></span><br>
    <button id="btn">开户</button><span id="sp4" style="color: green"></span>
    <input type="submit" id="sub" value="设置密码"  disabled>
</div>




</body>
</html>
